from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get("https://movie.douban.com/tv/")
print(driver.title)
# 类型
elem_lx = driver.find_element(By.XPATH,"/html/body/div[3]/div[1]/div/div[1]/div/div/div[1]/div/div[1]/div[2]")
elem_lx.click()
# 华语
elem_hy = driver.find_element(By.XPATH,"/html/body/div[3]/div[1]/div/div[1]/div/div/div[1]/div/div[1]/div[2]/div/div[2]/div/div/ul/li[2]/span")
elem_hy.click()
# 等五秒
driver.implicitly_wait(5)
elem_list_container = driver.find_element(By.CLASS_NAME,"explore-list")
elem_list = elem_list_container.find_elements(By.TAG_NAME,"li")
print(len(elem_list))
data_arr = []
for elem_data in elem_list:
    elem_a = elem_data.find_element(By.XPATH,"a")
    elem_img = elem_data.find_element(By.XPATH,"a/div/div[1]/div/img")
    src = elem_img.get_attribute("src")
    elem_name = elem_data.find_element(By.XPATH,"a/div/div[2]/div/div[1]/span")
    elem_subtitle = elem_data.find_element(By.XPATH,"a/div/div[2]/div/div[1]/div")
    obj = {"name":elem_name.text,"subtitle":elem_subtitle.text,"src":src,"href":elem_a.get_attribute("href")}
    data_arr.append(obj)
print(data_arr)
driver.close()